package com.etc.service;

import com.etc.entity.Advert;
import com.etc.entity.Notice;
import com.etc.mapper.AdvertMapper;
import com.etc.mapper.NoticeMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AdvertService {

    @Autowired
    private AdvertMapper advertMapper;

    public String advertAdd(@Param("advert_name")String advert_name,@Param("advert_image")String advert_image,@Param("advert_link")String advert_link){
        Advert advert = new Advert();
        advert.setAdvert_name(advert_name);
        advert.setAdvert_image(advert_image);
        advert.setAdvert_link(advert_link);
        advert.setAdvert_date(new Date());
        advertMapper.advertAdd(advert);
        return "添加广告成功";
    }
    public String advertDelete(int id){
        advertMapper.advertDelete(id);
        return "删除广告告成功";
    }
    public Advert advertQueryById(int id){
        Advert advert = advertMapper.advertQueryById(id);
        return advert;
    }

    public List<Advert> queryAll(){
        List<Advert> adverts = advertMapper.advertQueryAll();
        return adverts;
    }
    public String modify(@Param("advert_name")String advert_name,@Param("advert_image")String advert_image,@Param("advert_link")String advert_link,@Param("advert_id")int advert_id){
        Advert advert = new Advert();
        advert.setAdvert_name(advert_name);
        advert.setAdvert_id(advert_id);
        advert.setAdvert_image(advert_image);
        advert.setAdvert_link(advert_link);;
        advertMapper.advertModify(advert);
        return "修改公告成功";
    }
    public List<Advert> queryByName(String advert_name){
        List<Advert> adverts = advertMapper.advertQueryByName(advert_name);
        return adverts;
    }

}
